﻿using Domain.Entities;
using Domain.ValueObjects;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Infrastructure.Data.Configurations
{
    internal class UserConfiguration : IEntityTypeConfiguration<User>
    {
        public void Configure(EntityTypeBuilder<User> builder)
        {
            builder.ToTable("Users");
            builder.HasKey(u => u.Id);
            builder.Property(u => u.NickName).IsRequired().HasMaxLength(100);
            builder.Property(u => u.PhoneNumber).IsRequired().HasMaxLength(11);
            builder.Property(u => u.PasswordHash).IsRequired().HasMaxLength(100);
            
            //只读属性
            builder.Property(u => u.CreateTime).IsRequired();
            builder.Property(u => u.UpdateTime).IsRequired();

            builder.OwnsOne(s => s.AcademicInfo, aa =>
            {
                aa.Property(x => x.CollegeName).HasColumnName(nameof(AcademicInfo.CollegeName)).HasMaxLength(100);
                aa.Property(x => x.MajorName).HasColumnName(nameof(AcademicInfo.MajorName)).HasMaxLength(100);
            });
        }
    }
}
